<?php
/**
 * Sina sso client ajaxlogin
 * @package  SSOClient
 * @filename ajaxlogin.php
 * @author   lijunjie <junjie2@staff.sina.com.cn>
 * @date 	 2009-05-05
 * @version  1.2
 */

require_once('module/SSOConfig.class.php');
require_once('module/SSOClient.class.php');

$sso = new SSOClient();
if (isset($_REQUEST['framelogin'])) {
	$htmlHeader =  "<html><head><script language='javascript'>";
	$htmlFooter = "</script></head><body></body></html>";
}
$callback = $_REQUEST['callback'];
$noRedirect = $_REQUEST['noredirect'];

$js = "";
$arrUserInfo = array();
$jsoner = new Services_JSON();
if($sso->isLogined($noRedirect)){
	$arrUserInfo['result'] = true;
	if ($sso->getLoginType()) { // 确实登录了，返回用户信息
		$userInfo = $sso->getUserInfo();
		$arrUserInfo['userinfo']['uniqueid'] = $userInfo['uniqueid'];
		$arrUserInfo['userinfo']['userid'] = $userInfo['userid'];
		$arrUserInfo['userinfo']['displayname'] = $userInfo['displayname'];
		//.....
	}
	$js = $callback .'('.$jsoner->encode($arrUserInfo).');';
} else{
	$arrUserInfo['result'] = false;
	$arrUserInfo['errno'] = $sso->getErrno();
	$arrUserInfo['reason'] = $sso->getErrno() == $sso->E_SYSTEM?"系统繁忙，请稍后再试":$sso->getError();
	$js = $callback .'('.$jsoner->encode($arrUserInfo).');';
}
echo $htmlHeader. $js . $htmlFooter;
?>
